package data

import (
	"httpadmin/go-attribute/application/constant"
	"httpadmin/go-attribute/application/util"
	"strings"
)

type AndroidDeviceInfo struct {
	Common  CommonDeviceInfo
	Imei    string `form:"imei"`
	ImeiMd5 string `form:"imei_md5"`
	OaId    string `form:"oaid"`
}

func (data *AndroidDeviceInfo) GetDeviceMarks() []string {
	res := data.Common.GetDeviceMarks()
	if tmp := GetIMEIMark(data.Imei, data.ImeiMd5); tmp != "" {
		res = append(res, tmp)
	}

	if tmp := GetOaIdMark(data.OaId, ""); tmp != "" {
		res = append(res, tmp)
	}

	return res
}

func GetIMEIMark(imei, imeiMd5 string) string {
	if len(imeiMd5) == constant.MD5Len {
		return strings.ToLower(imeiMd5)
	}
	if imei == "" {
		return ""
	}
	return util.Md5LowerCase(imei)
}

func GetOaIdMark(oaId, oaIdMd5 string) string {
	if len(oaIdMd5) == constant.MD5Len {
		return strings.ToLower(oaIdMd5)
	}
	if oaId == "" {
		return ""
	}
	return util.Md5LowerCase(oaId)
}
